package com.wing.bill.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.bill.controller.admin.ReportUtil;
import com.wing.bill.dao.CabinetFormDao;
import com.wing.bill.dao.GetNewReportDao;
import com.wing.cabinet.model.response.CellInventoryInoutVO;
import com.wing.cabinet.model.response.StorageInventoryInoutVO;
import com.wing.cabinet.service.CellInventoryInoutService;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.LocalDateTimeUtils;
import com.wing.common.utils.PageResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GetNewReportServiceImpl implements GetNewReportService {
    @Autowired
    private GetNewReportDao getNewReportDao;
    @Autowired
    private CabinetFormDao cabinetFormDao;
    @Autowired
    private CellInventoryInoutService cellInventoryInoutService;

    @Override
    public JsonResult list(String param, String code) {
        HashMap hm = new HashMap();
        hm.put("title","物料领新统计(按天)");
        hm.put("data",getNewReportDao.list(ReportUtil.hundredDays().get(0),ReportUtil.hundredDays().get(1),code,param));
        return JsonResult.success(hm);
    }

    @Override
    public JsonResult topCell(String type, String startTime, String endTime, Integer click, String mainCabCode, String code) {
            if (StringUtils.isNotBlank(type)&&click==0){//顶部数据  固定时间
                HashMap map1 = new HashMap(){{put("title","领新数量(支)");put("sign","1");}};
                HashMap map2 = new HashMap(){{put("title","领新金额(元)");put("sign","2");}};
                HashMap map3 = new HashMap(){{put("title","售刀柜在库刀具数量(支)");put("sign","3");}};
                HashMap map4 = new HashMap(){{put("title","库存警告数(条)");put("sign","4");}};
                HashMap map5 = new HashMap(){{put("title","在库总价值(元)");put("sign","5");}};
                HashMap map6 = new HashMap(){{put("title","格子柜在库刀具数量");put("sign","6");}};//只看上新的
                HashMap map7 = new HashMap(){{put("title","领新人数");put("sign","7");}};
                HashMap map8 = new HashMap(){{put("title","领新机台数");put("sign","8");}};
                if (type.equals("0")){
                    map1.putAll(cabinetFormDao.queryNew(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),code,mainCabCode));//领新数量
                    map2.putAll(cabinetFormDao.queryNewAmount(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),code, mainCabCode));//领新金额
                    map6.putAll(getNewReportDao.findCabinetRequisitionNumber(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),code,mainCabCode));
                    map7.putAll(getNewReportDao.getNewPeopleNum(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),code,mainCabCode));//领新人数
                    map8.putAll(getNewReportDao.getNewDeviceNum(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),code,mainCabCode));//领新机台数量
                }else if (type.equals("1")){
                    map1.putAll(cabinetFormDao.queryNew(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),code, mainCabCode));//领新数量
                    map2.putAll(cabinetFormDao.queryNewAmount(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),code, mainCabCode));//领新金额
                    map6.putAll(getNewReportDao.findCabinetRequisitionNumber(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),code,mainCabCode));
                    map7.putAll(getNewReportDao.getNewPeopleNum(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),code,mainCabCode));//领新人数
                    map8.putAll(getNewReportDao.getNewDeviceNum(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),code,mainCabCode));//领新机台数量
                }else{
                    map1.putAll(cabinetFormDao.queryNew(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),code, mainCabCode));//领新数量
                    map2.putAll(cabinetFormDao.queryNewAmount(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),code,mainCabCode));//领新金额
                    map6.putAll(getNewReportDao.findCabinetRequisitionNumber(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),code,mainCabCode));
                    map7.putAll(getNewReportDao.getNewPeopleNum(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),code,mainCabCode));//领新人数
                    map8.putAll(getNewReportDao.getNewDeviceNum(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),code,mainCabCode));//领新机台数量
                }
                map3.putAll(cabinetFormDao.queryExist(code,mainCabCode));//售刀柜在库刀具数量 不随时间变化
                map4.putAll(cabinetFormDao.queryOtherGetNewReport(code,mainCabCode));//告警数量  不随时间变化
                map5.putAll(cabinetFormDao.queryExistAmount(code,mainCabCode));//售刀柜在库刀具总价值 不随时间变化
                List list = new ArrayList();
                list.add(map1);
                list.add(map2);
                list.add(map3);
                list.add(map4);
                list.add(map5);
                list.add(map6);
                return JsonResult.success("查询成功", list);
            }
            if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)&&click==0){//顶部数据  指定时间
                LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
                LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
                HashMap map1 = cabinetFormDao.queryNew(start,end,code, mainCabCode);;//领新数量
                map1.put("title","领新数量(支)");
                map1.put("sign","1");
                HashMap map2 = cabinetFormDao.queryNewAmount(start,end,code, mainCabCode);//领新金额
                map2.put("title","领新金额(元)");
                map2.put("sign","2");
                HashMap map3 = cabinetFormDao.queryExist(code, mainCabCode);//售刀柜在库刀具数量
                map3.put("title","售刀柜在库刀具数量(支)");
                map3.put("sign","3");
                HashMap map4 = cabinetFormDao.queryOtherGetNewReport(code, mainCabCode);//告警数量
                map4.put("title","库存警告数(条)");
                map4.put("sign","4");
                HashMap map5 = cabinetFormDao.queryExistAmount(code, mainCabCode);//在库刀具总价值
                map5.put("title","在库总价值(元)");
                map5.put("sign","5");
                HashMap map6 = getNewReportDao.findCabinetRequisitionNumber(start,end,code,mainCabCode);
                map6.put("title","格子柜在库刀具数量");
                map6.put("sign","6");
                List list = new ArrayList();
                list.add(map1);
                list.add(map2);
                list.add(map3);
                list.add(map4);
                list.add(map5);
                list.add(map6);
                return JsonResult.success("查询成功", list);
            }
            if (StringUtils.isNotBlank(type)&&click==1){//领新数量点击 固定时间
                if (type.equals("0")){
                    return JsonResult.success("查询成功",cabinetFormDao.queryNewQuantityClick(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),code,mainCabCode));
                }else if (type.equals("1")){
                    return JsonResult.success("查询成功",cabinetFormDao.queryNewQuantityClick(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),code, mainCabCode));
                }else{
                    return JsonResult.success("查询成功",cabinetFormDao.queryNewQuantityClick(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),code, mainCabCode));
                }
            }
            if (StringUtils.isNotBlank(type)&&click==3){//售刀柜在库刀具数量点击 固定时间
                return JsonResult.success("查询成功",cabinetFormDao.queryCellQuantityClick(code,mainCabCode));
            }
            if (StringUtils.isNotBlank(type)&&click==4){//库存告警数点击 固定时间
                return JsonResult.success("查询成功",cabinetFormDao.queryAlarmClickGetNewReport(code,mainCabCode));
            }
            if (StringUtils.isNotBlank(type)&&click==2){//领新金额点击 固定时间
                if (type.equals("0")){
                    return JsonResult.success("查询成功",cabinetFormDao.queryNewAmountClick(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),code,mainCabCode));
                }else if (type.equals("1")){
                    return JsonResult.success("查询成功",cabinetFormDao.queryNewAmountClick(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),code,mainCabCode));
                }else{
                    return JsonResult.success("查询成功",cabinetFormDao.queryNewAmountClick(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),code, mainCabCode));
                }
            }
            if (StringUtils.isNotBlank(type)&&click==5){//售刀柜在库刀具总价值点击 固定时间
                return JsonResult.success("查询成功",cabinetFormDao.queryExistAmountClick(code,mainCabCode));
            }
            if (StringUtils.isNotBlank(type)&&click==6){//主柜
                if (type.equals("0")){
                    return JsonResult.success("查询成功",getNewReportDao.findCabinetRequisitionNumberClick(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),code,mainCabCode));
                }else if (type.equals("1")){
                    return JsonResult.success("查询成功",getNewReportDao.findCabinetRequisitionNumberClick(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),code,mainCabCode));
                }else{
                    return JsonResult.success("查询成功",getNewReportDao.findCabinetRequisitionNumberClick(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),code,mainCabCode));
                }
            }

            if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)&&click==1){//领新数量点击 指定时间
                LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
                LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
                return JsonResult.success("查询成功",cabinetFormDao.queryNewQuantityClick(start,end,code, mainCabCode));
            }
            if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)&&click==3){//售刀柜在库刀具数量点击 指定时间
                return JsonResult.success("查询成功",cabinetFormDao.queryCellQuantityClick(code, mainCabCode));
            }
            if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)&&click==4){//库存告警数点击 指定时间
                return JsonResult.success("查询成功",cabinetFormDao.queryAlarmClickGetNewReport(code, mainCabCode));
            }
            if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)&&click==2){//领新金额点击 指定时间
                LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
                LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
                return JsonResult.success("查询成功",cabinetFormDao.queryNewAmountClick(start,end,code, mainCabCode));
            }
            if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)&&click==5){//售刀柜在库刀具总价值点击 指定时间
                return JsonResult.success("查询成功",cabinetFormDao.queryExistAmountClick(code, mainCabCode));
            }
            if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)&&click==6){//售刀柜在库刀具总价值点击 指定时间
                LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
                LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
                return JsonResult.success("查询成功",getNewReportDao.findCabinetRequisitionNumberClick(start,end,code,mainCabCode));
            }
            return JsonResult.fail("查询失败");
    }

    @Override
    public JsonResult midFirstChart(String type, String startTime, String endTime, String other, String param, String code, String mainCabCode) {
        HashMap hm1 = new HashMap();
        hm1.put("title","物料领新记录(按产品)");
        List<HashMap> list1 = new ArrayList<>();
        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(other.equals("oldSpec")){
                list1.addAll(cabinetFormDao.queryCabinetBySkuName(start,end,param,code, mainCabCode));//刀具消耗情况按刀具sku名称   修改为按原规格码  修改为物料规格
                hm1.put("avg",cabinetFormDao.queryCabinetBySkuNameAvg(start,end,param,code, mainCabCode));//平均值
            }else if(other.equals("type")){
                list1.addAll(cabinetFormDao.queryCabinetByTypeWeb(start,end,param,code, mainCabCode));//刀具消耗情况按类型 原型上是按工单 还没有工单 先用按类型
                hm1.put("avg",cabinetFormDao.queryCabinetByTypeAvg(start,end,param,code, mainCabCode));//平均值
            }else if(other.equals("category")){
                list1.addAll(cabinetFormDao.queryCabinetByCategory(start,end,param,code, mainCabCode));//刀具消耗情况按分类
                hm1.put("avg",cabinetFormDao.queryCabinetByCategoryAvg(start,end,param,code, mainCabCode));//平均值
            }else if(other.equals("brand")){
                list1.addAll(cabinetFormDao.queryCabinetByBrand(start,end,param,code, mainCabCode));//刀具消耗情况按品牌
                hm1.put("avg",cabinetFormDao.queryCabinetByBrandAvg(start,end,param,code, mainCabCode));//平均值
            }
        }
        if (type.equals("0")){
            if(other.equals("oldSpec")){
                list1.addAll(cabinetFormDao.queryCabinetBySkuName(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//刀具消耗情况按刀具sku名称   修改为按原规格码
                hm1.put("avg",cabinetFormDao.queryCabinetBySkuNameAvg(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("type")){
                list1.addAll(cabinetFormDao.queryCabinetByTypeWeb(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//刀具消耗情况按类型 原型上是按工单 还没有工单 先用按类型
                hm1.put("avg",cabinetFormDao.queryCabinetByTypeAvg(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("category")){
                list1.addAll(cabinetFormDao.queryCabinetByCategory(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//刀具消耗情况按分类
                hm1.put("avg",cabinetFormDao.queryCabinetByCategoryAvg(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("brand")){
                list1.addAll(cabinetFormDao.queryCabinetByBrand(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//刀具消耗情况按品牌
                hm1.put("avg",cabinetFormDao.queryCabinetByBrandAvg(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//平均值
            }
        }else if (type.equals("1")){
            if(other.equals("oldSpec")){
                list1.addAll(cabinetFormDao.queryCabinetBySkuName(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//刀具消耗情况按刀具sku名称   修改为按原规格码
                hm1.put("avg",cabinetFormDao.queryCabinetBySkuNameAvg(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("type")){
                list1.addAll(cabinetFormDao.queryCabinetByTypeWeb(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//刀具消耗情况按类型 原型上是按工单 还没有工单 先用按类型
                hm1.put("avg",cabinetFormDao.queryCabinetByTypeAvg(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("category")){
                list1.addAll(cabinetFormDao.queryCabinetByCategory(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//刀具消耗情况按分类
                hm1.put("avg",cabinetFormDao.queryCabinetByCategoryAvg(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("brand")){
                list1.addAll(cabinetFormDao.queryCabinetByBrand(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//刀具消耗情况按品牌
                hm1.put("avg",cabinetFormDao.queryCabinetByBrandAvg(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//平均值
            }
        }else if (type.equals("2")){
            if(other.equals("oldSpec")){
                list1.addAll(cabinetFormDao.queryCabinetBySkuName(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//刀具消耗情况按刀具sku名称   修改为按原规格码
                hm1.put("avg",cabinetFormDao.queryCabinetBySkuNameAvg(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("type")){
                list1.addAll(cabinetFormDao.queryCabinetByTypeWeb(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//刀具消耗情况按类型 原型上是按工单 还没有工单 先用按类型
                hm1.put("avg",cabinetFormDao.queryCabinetByTypeAvg(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("category")){
                list1.addAll(cabinetFormDao.queryCabinetByCategory(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//刀具消耗情况按分类
                hm1.put("avg",cabinetFormDao.queryCabinetByCategoryAvg(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//平均值
            }else if(other.equals("brand")){
                list1.addAll(cabinetFormDao.queryCabinetByBrand(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//刀具消耗情况按品牌
                hm1.put("avg",cabinetFormDao.queryCabinetByBrandAvg(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//平均值
            }
        }
        hm1.put("data",list1);
        return JsonResult.success("查询成功",hm1);
    }

    @Override
    public JsonResult midSecondChart(String type, String startTime, String endTime, String other, String param, String code, String mainCabCode) {
        HashMap hm3 = new HashMap();
        if(other.equals("person")){
            hm3.put("title","物料领新记录(按人员)");
        }else if(other.equals("device")){
            hm3.put("title","物料领新记录(按设备)");
        }
        List list3 = new ArrayList();
        List list = new ArrayList();
        HashMap map = new HashMap();
        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(other.equals("person")){
                list3.addAll(cabinetFormDao.queryCabinetByNameWeb(start,end,param,code,mainCabCode));//刀具消耗情况按人员
                hm3.put("avg",cabinetFormDao.queryCabinetByNameAvg(start,end,param,code,mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByNameWebTotal(start,end,param,code,mainCabCode));
            }else if(other.equals("device")){
                list3.addAll(cabinetFormDao.queryCabinetByMachineWeb(start,end,param,code,mainCabCode));//刀具消耗情况按使用该设备的机床
                hm3.put("avg",cabinetFormDao.queryCabinetByMachineAvg(start,end,param,code,mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByMachineWebTotal(start,end,param,code,mainCabCode));
            }else if(other.equals("dep")){
                list3.addAll(cabinetFormDao.queryCabinetByDep(start,end,param,code,mainCabCode));//刀具消耗情况按使用该设备的部门
                hm3.put("avg",cabinetFormDao.queryCabinetByDepAvg(start,end,param,code,mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByDepTotal(start,end,param,code,mainCabCode));
            }
        }
        if (type.equals("0")){
            if(other.equals("person")){
                list3.addAll(cabinetFormDao.queryCabinetByNameWeb(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//刀具消耗情况按人员
                hm3.put("avg",cabinetFormDao.queryCabinetByNameAvg(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByNameWebTotal(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code,mainCabCode));
            }else if(other.equals("device")){
                list3.addAll(cabinetFormDao.queryCabinetByMachineWeb(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//刀具消耗情况按使用该设备的机床
                hm3.put("avg",cabinetFormDao.queryCabinetByMachineAvg(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByMachineWebTotal(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code,mainCabCode));
            }else if(other.equals("dep")){
                list3.addAll(cabinetFormDao.queryCabinetByDep(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//刀具消耗情况按使用该设备的部门
                hm3.put("avg",cabinetFormDao.queryCabinetByDepAvg(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByDepTotal(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code,mainCabCode));
            }
        }else if (type.equals("1")){
            if(other.equals("person")){
                list3.addAll(cabinetFormDao.queryCabinetByNameWeb(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//刀具消耗情况按人员
                hm3.put("avg",cabinetFormDao.queryCabinetByNameAvg(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByNameWebTotal(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code,mainCabCode));
            }else if(other.equals("device")){
                list3.addAll(cabinetFormDao.queryCabinetByMachineWeb(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//刀具消耗情况按使用该设备的机床
                hm3.put("avg",cabinetFormDao.queryCabinetByMachineAvg(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByMachineWebTotal(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code,mainCabCode));
            }else if(other.equals("dep")){
                list3.addAll(cabinetFormDao.queryCabinetByDep(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//刀具消耗情况按使用该设备的部门
                hm3.put("avg",cabinetFormDao.queryCabinetByDepAvg(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByDepTotal(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code,mainCabCode));
            }
        }else if (type.equals("2")){
            if(other.equals("person")){
                list3.addAll(cabinetFormDao.queryCabinetByNameWeb(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//刀具消耗情况按人员
                hm3.put("avg",cabinetFormDao.queryCabinetByNameAvg(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByNameWebTotal(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code,mainCabCode));
            }else if(other.equals("device")){
                list3.addAll(cabinetFormDao.queryCabinetByMachineWeb(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//刀具消耗情况按使用该设备的机床
                hm3.put("avg",cabinetFormDao.queryCabinetByMachineAvg(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByMachineWebTotal(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code,mainCabCode));
            }else if(other.equals("dep")){
                list3.addAll(cabinetFormDao.queryCabinetByDep(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//刀具消耗情况按使用该设备的部门
                hm3.put("avg",cabinetFormDao.queryCabinetByDepAvg(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code, mainCabCode));//平均值
                map.putAll(getNewReportDao.queryCabinetByDepTotal(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code,mainCabCode));
            }
        }
        list.add(map);
        hm3.put("totalSumOne",list);
        hm3.put("data",list3);
        return JsonResult.success("查询成功",hm3);
    }


    @Override
    public JsonResult midThirdChart(String param, String type, String code, String startTime, String endTime, String mainCabCode) {
        HashMap hm3 = new HashMap();
        hm3.put("title","物料领新记录(按工单)");
        List list3 = new ArrayList();
        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            list3.addAll(getNewReportDao.midThirdChart(start,end,param,code,mainCabCode));//刀具消耗情况按工单
            hm3.put("avg",getNewReportDao.midThirdChartAvg(start,end,param,code,mainCabCode));//平均值
        }
        if (type.equals("0")){
            list3.addAll(getNewReportDao.midThirdChart(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code,mainCabCode));//刀具消耗情况按工单
            hm3.put("avg",getNewReportDao.midThirdChartAvg(ReportUtil.dayUtil().get(0),ReportUtil.dayUtil().get(1),param,code,mainCabCode));//平均值
        }else if (type.equals("1")){
            list3.addAll(getNewReportDao.midThirdChart(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code,mainCabCode));//刀具消耗情况按工单
            hm3.put("avg",getNewReportDao.midThirdChartAvg(ReportUtil.weekUtil().get(0),ReportUtil.weekUtil().get(1),param,code,mainCabCode));//平均值
        }else if (type.equals("2")){
            list3.addAll(getNewReportDao.midThirdChart(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code,mainCabCode));//刀具消耗情况按工单
            hm3.put("avg",getNewReportDao.midThirdChartAvg(ReportUtil.dateUtil().get(0),ReportUtil.dateUtil().get(1),param,code,mainCabCode));//平均值
        }
        hm3.put("data",list3);
        return JsonResult.success(hm3);
    }


    @Override
    public JsonResult topCellNew(String startTime, String endTime, Integer click, String mainCabCode, String code) {
        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)) {//顶部数据  指定时间

            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime, "yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime, "yyyy-MM-dd HH:mm:ss");

            if (click==0){
                HashMap map1 = cabinetFormDao.queryNew(start, end, code, mainCabCode);
                ;//领新数量
                map1.put("title", "领新数量(支)");
                map1.put("sign", "1");
                HashMap map2 = cabinetFormDao.queryNewAmount(start, end, code, mainCabCode);//领新金额
                map2.put("title", "领新金额(元)");
                map2.put("sign", "2");
                HashMap map3 = getNewReportDao.getNewPeopleNum(start,end,code,mainCabCode);
                map3.put("title","领新人数");
                map3.put("sign","3");
                HashMap map4 = getNewReportDao.getNewDeviceNum(start,end,code,mainCabCode);
                map4.put("title","领新机台数");
                map4.put("sign","4");

                List list = new ArrayList();
                list.add(map1);
                list.add(map2);
                list.add(map3);
                list.add(map4);
                return JsonResult.success("查询成功", list);
            } else if (click==1) {//领新数量点击
                return JsonResult.success("查询成功", cabinetFormDao.queryNewQuantityClick(start, end, code, mainCabCode));
            } else if (click==2) {//领新金额点击
                return JsonResult.success("查询成功",cabinetFormDao.queryNewAmountClick(start,end,code, mainCabCode));
            } else if (click==3) {//领新人数点击
                return JsonResult.success("查询成功",getNewReportDao.getNewPeopleNumClick(start,end,code,mainCabCode));
            } else if (click==4) {//领新机台数点击
                return JsonResult.success("查询成功",getNewReportDao.getNewDeviceNumClick(start,end,code,mainCabCode));
            }

        }

        return JsonResult.fail("查询失败");
    }

    @Override
    public JsonResult midFirstChartNew(String startTime, String endTime, String selectParam, String param, String code, String mainCabCode,String tab) {
        HashMap hm = new HashMap();
        hm.put("title","物料领新情况(按物料)");
        List<HashMap> list = new ArrayList<>();

        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            if(selectParam.equals("spu")){
                if ("tab1".equals(tab)){
                    hm.put("title","物料领新情况(按系列SPU)");
                }
                list.addAll(cabinetFormDao.querySpuAndSku(start,end,selectParam,param,code, mainCabCode));//刀具消耗情况按spu
                hm.put("avg",cabinetFormDao.querySpuAndSkuAvg(start,end,selectParam,param,code, mainCabCode));//平均值
            } else if (selectParam.equals("sku")) {
                if ("tab1".equals(tab)){
                    hm.put("title","物料领新情况(按系列SKU)");
                }
                list.addAll(cabinetFormDao.querySpuAndSku(start,end,selectParam,param,code, mainCabCode));//刀具消耗情况按sku
                hm.put("avg",cabinetFormDao.querySpuAndSkuAvg(start,end,selectParam,param,code, mainCabCode));//平均值
            } else if(selectParam.equals("type")){
                if ("tab1".equals(tab)){
                    hm.put("title","物料领新情况(按类型)");
                }
                list.addAll(cabinetFormDao.queryCabinetByTypeWeb(start,end,param,code, mainCabCode));//刀具消耗情况按类型
                hm.put("avg",cabinetFormDao.queryCabinetByTypeAvg(start,end,param,code, mainCabCode));//平均值
            }else if(selectParam.equals("category")){
                if ("tab1".equals(tab)){
                    hm.put("title","物料领新情况(按分类)");
                }
                list.addAll(cabinetFormDao.queryCabinetByCategory(start,end,param,code, mainCabCode));//刀具消耗情况按分类
                hm.put("avg",cabinetFormDao.queryCabinetByCategoryAvg(start,end,param,code, mainCabCode));//平均值
            }else if(selectParam.equals("brand")){
                if ("tab1".equals(tab)){
                    hm.put("title","物料领新情况(按品牌)");
                }
                list.addAll(cabinetFormDao.queryCabinetByBrand(start,end,param,code, mainCabCode));//刀具消耗情况按品牌
                hm.put("avg",cabinetFormDao.queryCabinetByBrandAvg(start,end,param,code, mainCabCode));//平均值
            }
        }

        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult midSecondChartNew(String startTime, String endTime, String selectParam, String param, String code, String mainCabCode,String tab) {
        HashMap hm = new HashMap();
        if ("tab0".equals(tab)){
            hm.put("title","物料领新情况(按柜子)");
        } else if ("tab1".equals(tab) && "main".equals(selectParam)) {
            hm.put("title","物料领新情况(按主柜)");
        } else if ("tab1".equals(tab) && "desk".equals(selectParam)) {
            hm.put("title","物料领新情况(按副柜)");
        }

        List<HashMap> list = new ArrayList<>();
        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)) {
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime, "yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime, "yyyy-MM-dd HH:mm:ss");

            list.addAll(getNewReportDao.getNewByParam(start,end,code,selectParam,param,mainCabCode));
        }

        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult midThirdChartNew(String startTime, String endTime, String selectParam, String param, String code, String mainCabCode,String tab) {
        HashMap hm = new HashMap();
        if ("tab0".equals(tab)) {
            hm.put("title", "物料领新情况(按组织)");
        } else if ("tab1".equals(tab) && "person".equals(selectParam)) {
            hm.put("title", "物料领新情况(按领用人)");
        } else if ("tab1".equals(tab) && "department".equals(selectParam)) {
            hm.put("title", "物料领新情况(按部门)");
        } else if ("tab1".equals(tab) && "costCenter".equals(selectParam)) {
            hm.put("title", "物料领新情况(按成本中心)");
        }
        List<HashMap> list = new ArrayList<>();
        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)) {
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime, "yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime, "yyyy-MM-dd HH:mm:ss");

            list.addAll(getNewReportDao.getNewByParam(start,end,code,selectParam,param,mainCabCode));
            hm.put("avg",getNewReportDao.getAvg(start,end,code,selectParam,param,mainCabCode));
            if ("department".equals(selectParam)||"costCenter".equals(selectParam)){
                hm.put("totalSum",getNewReportDao.getTotal(start,end,code,param,mainCabCode));
            }
        }

        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public JsonResult midFourChartNew(String startTime, String endTime, String selectParam, String param, String code, String mainCabCode,String tab) {
        HashMap hm = new HashMap();
        if ("tab0".equals(tab)) {
            hm.put("title", "物料领新情况(按使用情况)");
        } else if ("tab1".equals(tab) && "workOrder".equals(selectParam)) {
            hm.put("title", "物料领新情况(按工单)");
        } else if ("tab1".equals(tab) && "workShop".equals(selectParam)) {
            hm.put("title", "物料领新情况(按车间)");
        } else if ("tab1".equals(tab) && "device".equals(selectParam)) {
            hm.put("title", "物料领新情况(按设备)");
        }
        List<HashMap> list = new ArrayList<>();
        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)) {
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime, "yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime, "yyyy-MM-dd HH:mm:ss");

            if ("workOrder".equals(selectParam)){
                list.addAll(getNewReportDao.midThirdChart(start,end,param,code,mainCabCode));//刀具消耗情况按工单
                hm.put("avg",getNewReportDao.midThirdChartAvg(start,end,param,code,mainCabCode));//平均值
            }else {
                list.addAll(getNewReportDao.getNewByParam(start,end,code,selectParam,param,mainCabCode));
                hm.put("avg",getNewReportDao.getAvg(start,end,code,selectParam,param,mainCabCode));
            }
        }

        hm.put("data",list);
        return JsonResult.success("查询成功",hm);
    }

    @Override
    public PageResult data(String type, String startTime, String endTime, Integer page, Integer limit, String sort, String order,String mainCabCode) {
        if(StringUtils.isNotBlank(type)){
            if (type.equals("0")){
                Page<CellInventoryInoutVO> pg = new Page<>(page, limit);
                Map queryParam=new HashMap();
                queryParam.put("sort", StrUtil.toUnderlineCase(sort));
                queryParam.put("order",order);
                queryParam.put("startCreateTime",ReportUtil.dayUtil().get(0).toString());
                queryParam.put("endCreateTime",ReportUtil.dayUtil().get(1).toString());
                queryParam.put("mainCabCode",mainCabCode);
                IPage<CellInventoryInoutVO> list = cellInventoryInoutService.pageList(pg,queryParam);
                return new PageResult<>(list.getRecords(), list.getTotal());
            }else if (type.equals("1")){
                Page<CellInventoryInoutVO> pg = new Page<>(page, limit);
                Map queryParam=new HashMap();
                queryParam.put("sort",StrUtil.toUnderlineCase(sort));
                queryParam.put("order",order);
                queryParam.put("startCreateTime",ReportUtil.weekUtil().get(0).toString());
                queryParam.put("endCreateTime",ReportUtil.weekUtil().get(1).toString());
                queryParam.put("exportType",1);
                queryParam.put("mainCabCode",mainCabCode);
                IPage<CellInventoryInoutVO> list = cellInventoryInoutService.pageList(pg,queryParam);
                return new PageResult<>(list.getRecords(), list.getTotal());
            }else{
                Page<CellInventoryInoutVO> pg = new Page<>(page, limit);
                Map queryParam=new HashMap();
                queryParam.put("sort",StrUtil.toUnderlineCase(sort));
                queryParam.put("order",order);
                queryParam.put("startCreateTime",ReportUtil.dateUtil().get(0).toString());
                queryParam.put("endCreateTime",ReportUtil.dateUtil().get(1).toString());
                queryParam.put("exportType",1);
                queryParam.put("mainCabCode",mainCabCode);
                IPage<CellInventoryInoutVO> list = cellInventoryInoutService.pageList(pg,queryParam);
                return new PageResult<>(list.getRecords(), list.getTotal());
            }
        }
        if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            LocalDateTime start = LocalDateTimeUtils.convertStringToLDT(startTime,"yyyy-MM-dd HH:mm:ss");
            LocalDateTime end = LocalDateTimeUtils.convertStringToLDT(endTime,"yyyy-MM-dd HH:mm:ss");
            Page<CellInventoryInoutVO> pg = new Page<>(page, limit);
            Map queryParam=new HashMap();
            queryParam.put("sort",StrUtil.toUnderlineCase(sort));
            queryParam.put("order",order);
            queryParam.put("startCreateTime",start.toString());
            queryParam.put("endCreateTime",end.toString());
            queryParam.put("exportType",1);
            IPage<CellInventoryInoutVO> list = cellInventoryInoutService.pageList(pg,queryParam);
            return new PageResult<>(list.getRecords(), list.getTotal());
        }
        return null;
    }


}
